package com.zkyc.framework.common.mapper;

import com.zkyc.framework.common.pojo.Website;
import org.apache.ibatis.annotations.Mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (Website)表数据库访问层
 *
 * @author libingchuan
 * @since 2022-05-23 16:22:06
 */
@Mapper
public interface WebsiteMapper extends BaseMapper<Website> {
    @Select("select id from web_website where is_deleted = 0 ORDER BY id desc limit 1")
    int getMaxWebsiteId();

    @Select({
            "<script>",
            "SELECT  *  from  web_website b where b.id=(select a.website_id from system_website_ref_role a  where  role_id=#{roleId}) and is_deleted=0",
            "</script>"
    })
    Website getWebsiteByRoleId(@Param("roleId") Integer roleId);

    @Select({
            "<script>",
            "SELECT * FROM web_website c,( SELECT DISTINCT website_id FROM system_user_ref_role a, system_website_ref_role b WHERE user_id =#{userId}  AND a.role_id = b.role_id ) d \n" +
                    "WHERE c.id = d.website_id  and c.is_deleted=0 order by c.gmt_updated DESC",
            "</script>"
    })
    List<Website> getUserWebsiteList(@Param("userId") String userId);
}

